﻿/* 脚本定制 50009219 */
/* 脚本美化 技术顾问 */

var status = -1;

function start() {
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == 0) {
        cm.dispose();
        return;
    }
    status++;
    if (status == 0) {
        text = "\t\t\t#b#L0#突破上限排行榜#l\r\n";
        cm.sendSimple(text);
    } else if (status == 1) {
        if (selection == 0) {
            var conn = cm.getConnection();
            var sql = "SELECT ii.limitbreak,i.itemid, c.name FROM inventoryitems i, inventoryequipment ii, characters c WHERE c.id = i.characterid AND ii.inventoryitemid = i.inventoryitemid AND limitbreak > 0 ORDER BY limitbreak DESC LIMIT 0, 100";
            var pstmt = conn.prepareStatement(sql);
            var rs = pstmt.executeQuery();
            rankingData = new Array();
            while (rs.next()) {
                var data = {};
                data.name = rs.getString("name");
                data.itemid = rs.getInt("itemid");
                data.limitbreak = rs.getInt("limitbreak");
                rankingData.push(data);
            }
            rs.close();
            pstmt.close();
            var text = "\t\t\t\t#e#d★ 突破上限排行 ★#k#n\r\n\r\n";
            text += "\t#e名次#n\t#e玩家昵称#n\t\t  #e突破上限的武器及伤害#n\r\n";
            for (var i = 0; i < rankingData.length; i++) {
                if (i + 1 == 1) {
                    text += "#r";
                } else if (i + 1 == 2) {
                    text += "#g";
                } else if (i + 1 == 3) {
                    text += "#b";
                }
                text += "\t " + (i + 1) + "\t\t ";

                // 填充名字空格
                text += rankingData[i].name;
                var itemid = rankingData[i].itemid;
                for (var j = 16 - rankingData[i].name.toString().getBytes().length; j > 0 ; j--) {
                    text += " ";
                }
                var limitBreak = rankingData[i].limitbreak;
                var limitBreakText = limitBreak;
                if (limitBreak > 99999999) {
                    var currentBreak = new Number(limitBreak / 100000000).toFixed(3);
                    limitBreakText = currentBreak + "亿";
                } else if (limitBreak > 9999999 && limitBreak < 100000000) {
                    var currentBreak = new Number(limitBreak / 10000000).toFixed(3);
                    limitBreakText = currentBreak + "千万";
                } else if (limitBreak > 99999 && limitBreak < 10000000) {
                    var currentBreak = new Number(limitBreak / 10000).toFixed(3);
                    limitBreakText = currentBreak + "万";
                }
                text += "\t #v" + itemid + "#" + limitBreakText;

                text += "\r\n";
            }
            cm.sendOkS(text, 2);
            cm.dispose();
        }
    }
}